<template>
  <el-table :data="list" style="width: 100%;padding-top: 15px;">
    <el-table-column label="登录用户" min-width="200">
      <template slot-scope="scope">
        {{ scope.row.name | nameFilter }}
      </template>
    </el-table-column>
    <el-table-column label="IP地址" width="195" align="center">
      <template slot-scope="scope">
        {{ scope.row.ipAddress }}
      </template>
    </el-table-column>
    <el-table-column label="状态" width="100" align="center">
      <template slot-scope="{ row }">
        <el-tag :type="row.status | statusFilter">
          {{ row.status }}
        </el-tag>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        success: "success",
        pending: "danger"
      };
      return statusMap[status];
    },
    nameFilter(str) {
      return str.substring(0, 30);
    }
  },
  data() {
    return {
      list: null
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.list = [
        {
          name: "Admin ",
          status: "success",
          ipAddress: "10.10.10.111"
        },
        {
          name: "demo 1",
          status: "danger",
          ipAddress: "127.10.10.111"
        }
      ];
    }
  }
};
</script>
